import React, { Component } from 'react'
import ReactDOM from 'react-dom' //千万注意: 使用Portal技术,引入react-dom时,千万不要加/client
export default class Test extends Component {
  constructor() {
    super()
    this.aaa = document.createElement('div')
  }
  render() {
    // 会自动根据jsx生成虚拟dom.根据虚拟dom创建真实dom.并把真实dom添加到this.aaa里面
    return ReactDOM.createPortal(<div>Test</div>, this.aaa)
  }

  componentDidMount() {
    document.getElementById('xxx').appendChild(this.aaa)
  }
  componentWillUnmount() {
    document.getElementById('xxx').removeChild(this.aaa)
  }
}
